# @Author: Eric Ito
# @Date: 1/30/2009
# @Name: Project Euler Problem 39


"""
If p is the perimeter of a right angle triangle with integral length
sides, {a,b,c}, there are exactly three solutions for p = 120.

{20,48,52}, {24,45,51}, {30,40,50}

For which value of p <= 1000, is the number of solutions maximised?
"""

"""
if max value of p is 1000, then max hypotenuse value is 500

max_hyp = 500
max_hyp_2 = 500^2 = 2500
2500 = a^2 + b^2
"""

def main():
    TRI = {}
    for p in range(1,1001):
        max_hyp = p/2               # 500 for p = 1000
        max_hyp_2 = max_hyp*max_hyp # 2500 for p = 1000
        TRI[p] = 0
        for c in range(1,p/2):
            for b in range(1,(p-c)/2):
                a = p - c - b
                if a**2 + b**2 == c**2:
                    TRI[p] += 1 #.append((a,b,c))
    maxS = 0
    maxP = 0
    for key in TRI.keys():
        if TRI[key] > maxS:
            maxS = TRI[key]
            maxP = key
    print "Most solutions =",maxS,"at P =",maxP



if __name__ == "__main__":
    main()